<%@page contentType="text/html;charset=utf-8" %>
<%@taglib prefix="s" uri="/struts-tags" %>   
<script type="text/javascript">
function sys_savecpaccount(type)
{
    var act_id = document.getElementById("act_id").value;
    var act_name = document.getElementById("act_name").value;
    var act_password = document.getElementById("act_password").value;
    var account_type = dijit.byId("account_type").get('value');
    var act_remark = document.getElementById("act_remark").value;
    var account_cpid = dijit.byId("act_cpid").get('value');
    var account_channelid = dijit.byId("act_channelid").get('value');
    if (act_id == null || act_id == "" || 
            act_name == null || act_name == "" || 
            act_password == null || act_password == "" || 
            account_type == null || account_type == "")
    {
        alert("信息不完整！");
        return false;
    }
    if(account_type==0)
    {
        if(account_cpid<=0)
        {
        	alert("信息不完整！");
            return false;
        }
    }
    else
    {
    	 if(account_channelid<=0)
         {
         	alert("信息不完整！");
             return false;
         }
    }
    if (!confirm("确定继续？"))
    {
        return false;
    }
    var url = "rs/cpaccount/save.do";
    var content = "type=" + type
                + "&cpaccount.id=" + act_id
                + "&cpaccount.name=" + act_name
                + "&cpaccount.password=" + act_password
                + "&cpaccount.type=" + account_type
                + "&cpaccount.cpId="+account_cpid
                + "&cpaccount.channelid="+account_channelid
                + "&cpaccount.remark="+act_remark;
    var objectid = "sys_cpaccount";
    sendXMLHttpRequest(url, content, objectid); 
}

function sys_listcpaccount()
{
    var url = "rs/cpaccount/list.do";
    var content = "";
    var objectid = "content";
    sendXMLHttpRequest(url, content, objectid); 
}
function account_type_onchange()
{
	 var account_type = dijit.byId("account_type").get('value');
	 if(account_type==0)
	 {
		 document.getElementById("cpdiv").style.display="";
		 document.getElementById("channeldiv").style.display="none";
	 }else
	 {
		 document.getElementById("cpdiv").style.display="none";
		 document.getElementById("channeldiv").style.display="";
	 }
}
</script>
 <table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="5"></td>
    <td>   
  <form id="myform">
  <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td colspan="3">
        <table width="100%"  border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td><img src="images/table_top_left.jpg" width="20" height="15" /></td>
            <td><img src="images/table_top_bg.jpg" width="770" height="15"/></td>
            <td align="right">
              <img src="images/table_top_right.jpg" width="20" height="15" /></td>
          </tr>
        </table>
      </td>
    </tr>
    <tr>
      <td height="25" colspan="3" class="table_blue">
        <strong><img src="images/dot.jpg" width="13" height="9">账号信息</strong></td>
    </tr> 
    <tr>
      <td class="table_w1" width="10%">&nbsp;<font color="red">(*)</font>ID：</td>
      <td class="table_w2" width="90%" colspan="2">&nbsp;
        <input id="act_id" type="text" size="60" 
          value="<s:property value="cpaccount.id" />" <s:if  test="type.equals('update')" >readonly="readonly"</s:if> /></td>
    </tr>
    <tr>
      <td class="table_w1">&nbsp;<font color="red">(*)</font>名称：</td>
      <td class="table_w2" colspan="2">&nbsp;
        <input id="act_name" type="text" size="60" 
          value="<s:property value="cpaccount.name" />"/></td>
    </tr>
    <s:if test="account.id.length()>0">
        <input id="act_password" type="hidden" value="<s:property value="account.password" />" />
    </s:if>
    <s:else>
    <tr <s:if test="type.equals('update')">style="display:none;"</s:if>>
      <td class="table_w1">&nbsp;<font color="red">(*)</font>密码：</td>
      <td class="table_w2" colspan="2">&nbsp;
        <input id="act_password" type="text" size="60"
          value="<s:property value="cpaccount.password" />" />&nbsp;&nbsp;<button id="btn5" dojoType="dijit.form.Button"
            onclick="generate_passowrd('act_password');">随机密码</button></td>
    </tr>
    </s:else>
    <tr>
      <td class="table_w1">&nbsp;<font color="red">(*)</font>类型：</td>
      <td class="table_w2" colspan="2">&nbsp;
      <select id="account_type" dojoType="dijit.form.FilteringSelect" style="width:290px;" onchange="account_type_onchange()">
        <option value="0" <s:if test="cpaccount.type==0">checked</s:if>>CP用户</option>
        <option value="1" <s:if test="cpaccount.type==1">checked</s:if>>渠道用户</option>
      </select>
    </tr>
	    <tr id="cpdiv" name="cpdiv" <s:if test="cpaccount.type==1">style="display:none;"</s:if>>
	      <td class="table_w1">&nbsp;<font color="red">(*)</font>cp：</td>
	      <td class="table_w2" colspan="2">&nbsp;
	      <select id="act_cpid" name="act_cpid" dojoType="dijit.form.FilteringSelect" style="width:290px;">
	        <option value="0"></option>
	      <s:if test="cpInfos.size()>0" >
	        <s:iterator value="cpInfos" status="stat">
	        <option value="<s:property value="id" />" 
	            <s:if test="id.equals(cpaccount.cpId)" >selected</s:if> ><s:property value="cpName" /></option>
	        </s:iterator>
	      </s:if>
	      </select>
	    </tr>
	     <tr id="channeldiv" name="channeldiv" <s:if test="type.equals('insert')">style="display:none;"</s:if> <s:if test="cpaccount.type==0">style="display:none;"</s:if>>
	      <td class="table_w1">&nbsp;<font color="red">(*)</font>渠道：</td>
	      <td class="table_w2" colspan="2">&nbsp;
	      <select id="act_channelid" name="act_channelid" dojoType="dijit.form.FilteringSelect" style="width:290px;">
	        <option value="0"></option>
	      <s:if test="channels.size()>0" >
	        <s:iterator value="channels" status="stat">
	        <option value="<s:property value="id" />" 
	            <s:if test="id.equals(cpaccount.channelid)" >selected</s:if> ><s:property value="name" /></option>
	        </s:iterator>
	      </s:if>
	      </select>
	    </tr>
    <tr>
      <td class="table_w1">&nbsp;<font color="red">(*)</font>备注：</td>
      <td class="table_w2" colspan="2">&nbsp;
      <textarea rows="5" cols="30" id="act_remark" name="act_remark"><s:property value="cpaccount.remark"/></textarea>
    </tr>
    <tr>
      <td colspan="3" class="table_w1" align="center">
        <s:if test="type.equals('insert')">
        <button id="btn2" dojoType="dijit.form.Button"
            onclick="sys_savecpaccount('insert');">添加</button>
        </s:if>
        <s:else>
        <button id="btn2" dojoType="dijit.form.Button"
            onclick="sys_savecpaccount('update');">修改</button>
        &nbsp;&nbsp;        
        <button id="btn3" dojoType="dijit.form.Button"
            onclick="sys_savecpaccount('delete');">删除</button>
        </s:else>
        &nbsp;&nbsp;        
        <button id="btn4" dojoType="dijit.form.Button"
            onclick="sys_listcpaccount();">返回</button>
      </td>      
    </tr>
    <tr> 
      <td colspan="7" background="images/table_bom_bg.jpg">
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td><img src="images/table_bom_left.jpg" width="20" height="15"></td>
          <td></td>
          <td align="right">
            <img src="images/table_bom_right.jpg" width="20" height="15"></td>
        </tr>
        </table>
      </td>
    </tr>
  </table>  
  </form>
  </td>
  <td width="5"></td>
  </tr>
  </table>